package com.metaera.app.ui.activities;

import android.os.Bundle;

import com.lxj.xpopup.XPopup;
import com.metaera.app.R;
import com.metaera.app.controller.core.IPaginationPresenter;
import com.metaera.app.controller.presenter.TodayEventListPresenter;
import com.metaera.app.controller.view.BasicPaginationView;
import com.metaera.app.controller.view.RefreshLoadMoreView;
import com.metaera.app.controller.view.core.IPaginationView;
import com.metaera.app.data.model.TodayEventResponse;
import com.metaera.app.data.network.ApiParam;
import com.metaera.app.ui.adapters.TodayEventListAdapter;
import com.metaera.app.ui.core.BaseRequestActivity;
import com.metaera.app.ui.popup.SharePopup;
import com.metaera.app.utils.ViewUtils;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;

import androidx.recyclerview.widget.RecyclerView;

public class TodayEventActivity extends BaseRequestActivity {

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_today_event;
    }

    @Override
    protected void initialize(Bundle savedInstanceState) {
        ViewUtils.addStatusBarHeightPadding(findViewById(R.id.layout_container));

        // find
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        SmartRefreshLayout refreshLayout = findViewById(R.id.smart_refresh_layout);

        // init view
        refreshLayout.setEnableRefresh(false);
        recyclerView.setAdapter(new TodayEventListAdapter());

        // network
        IPaginationPresenter<IPaginationView<TodayEventResponse>, TodayEventResponse>
                presenter = new TodayEventListPresenter();
        presenter.setModelAndView(new BasicPaginationView<>(recyclerView, refreshLayout, this));
        presenter.requestRefresh();

        // listener
        findViewById(R.id.iv_arrow_back).setOnClickListener(v -> finish());
        refreshLayout.setOnRefreshLoadMoreListener(new RefreshLoadMoreView<>(presenter));
        findViewById(R.id.iv_share).setOnClickListener(v -> {

            new XPopup.Builder(v.getContext())
                    .asCustom(
                            new SharePopup(
                                    v.getContext(),
                                    "今日大事件-Meta Era",
                                    "每天十分钟，了解今日大事件",
                                    ApiParam.LINK_SHARE_2,
                                    R.drawable.a_ic_today_event_bg
                            )
                    )
                    .show();

        });
    }

}
